package com.example.powersystem.controller;

import com.example.powersystem.dao.TowerMapper;
import com.example.powersystem.pojo.Tower;
import com.example.powersystem.service.TowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author smd
 * @since 2022-08-04
 */
@Api(value = "杆塔", description = "杆塔测试接口")
@RestController
@RequestMapping("/tower")
public class TowerController {
    @Resource
    private TowerMapper towerMapper;
    @Resource
    private TowerService towerService;

    //添加-测试
    @ApiOperation(value="添加杆塔", notes="添加杆塔")
    @ApiImplicitParam(name = "tower", value = "杆塔添加信息", required = true, dataType = "Tower")
    @RequestMapping(value = "/addTower")
    public int addTower(@RequestBody Tower tower){
//        Tower t=new Tower();
//        t.setCode("a233211231");
//        t.setBelongLine("111");
//        t.setCreateDate(new Date());
//        t.setCreateUser(2);
        int count=towerMapper.insert(tower);
        return count;
    }

    //修改-测试
    @RequestMapping("/updTower")
    public int updTower(){
        Tower t=new Tower();
        t.setCode("2222222222");
        t.setBelongLine("1115");
        t.setUpdateDate(new Date());
        t.setUpdateUser(2);

        int count=towerMapper.updateById(t);
        return count;
    }
    //查询全部
    @RequestMapping("/selectAll")
    public List<Tower> selectAll(){
        return towerMapper.selectAll();
    }
    //根据所属线路和状态查询
    @RequestMapping("/selectByT")
    public List<Tower> selectByT(){
        System.out.println("数量："+towerService.selectByLineAndStatus("111",1).size());
        return towerService.selectByLineAndStatus("111",1);
    }
    //根据杆塔编号删除数据
    @RequestMapping("/delTower")
    public int delTower(){
        int count=towerMapper.deleteById("a233211231");
        return count;
    }

}
